package com.codemeta.bokit.mybatis.core.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codemeta.bokit.mybatis.core.mapper.BaseMapperX;
import com.codemeta.bokit.mybatis.core.page.PageX;

/**
 * mybatis-plus基础业务接口基础实现类对象
 *
 * @author hice
 * @date 2021/11/19
 */
public class BaseServiceImpl<M extends BaseMapperX<T>, T> extends ServiceImpl<M, T> implements BaseService<T> {

    /**
     * 重写方法支持save前置检查
     *
     * @param entity .
     * @return .
     */
    @Override
    public boolean save(T entity) {
        return beforeSave(entity) && super.save(entity);
    }

    /**
     * 重写方法支持updateById前置检查
     *
     * @param entity .
     * @return .
     */
    @Override
    public boolean updateById(T entity) {
        return beforeUpdateById(entity) && super.updateById(entity);
    }

    @Override
    public Page<T> pageX(PageX page, Wrapper<T> queryWrapper) {
        return getBaseMapper().selectPageX(page, queryWrapper);
    }
}